﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ERPTOOLS.Class;

namespace ERPTOOLS
{
    public partial class Transfer : Form
    {
        public Transfer()
        {
            InitializeComponent();
        }

        private void Transfer_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void btnnext_Click(object sender, EventArgs e)
        {
            if (dateTimePicker1.Value==null || dateTimePicker4.Value == null)
            {
                MessageBox.Show("开始时间不可空白");
            }
            if (radioButton1.Checked)
            {
                radioButton1.Checked = false;
                radioButton1.Checked = true;
            }
            if (radioButton2.Checked)
            {
                radioButton2.Checked = false;
                radioButton2.Checked = true;
            }
            if (radioButton3.Checked)
            {
                radioButton3.Checked = false;
                radioButton3.Checked = true;
            }
            if (radioButton4.Checked)
            {
                radioButton4.Checked = false;
                radioButton4.Checked = true;
            }
            if (radioButton5.Checked)
            {
                radioButton5.Checked = false;
                radioButton5.Checked = true;
            }
            this.Visible = false;
            Main_Run mr = new Main_Run(this);
            mr.Show();
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                label1.Visible = true;
                richTextBox1.Visible = true;
                checkBox2.Visible = false;
                checkBox3.Visible = false;
                groupBox2.Visible = false;
                label3.Visible = true;
                label4.Visible = true;
                textBox1.Visible = true;
                textBox2.Visible = true;
                checkBox1.Text = "品号信息抛转";
                checkBox2.Visible=false;
                label1.Text = "提取品号信息";
                checkBox1.Checked =  Convert.ToBoolean(XMLHelper.GetInnerTextByXpath("Configure.xml", "//ItemCheck"));
                richTextBox1.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//ItemLift")).ToString().Replace("<", "&lt;").Replace(">", "&gt;");
                richTextBox2.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//ItemUpdate")).ToString().Replace("<", "&lt;").Replace(">", "&gt;");
                textBox1.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//ItemUpdateDB"));
                textBox2.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//ItemUpdateField"));
                dateTimePicker1.Text=(XMLHelper.GetInnerTextByXpath("Configure.xml", "//ItemStrDate"));
                dateTimePicker2.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//ItemEndDate"));
                comboBox1.Text=(XMLHelper.GetInnerTextByXpath("Configure.xml", "//ItemCYC"));
                numericUpDown1.Text = XMLHelper.GetInnerTextByXpath("Configure.xml", "//ItemInterval");
                textBox3.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//ItemExecute"));
            }
            else
            {
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferItem", "ItemCheck", checkBox1.Checked.ToString());
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferItem", "ItemLift", richTextBox1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferItem", "ItemUpdate", richTextBox2.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferItem", "ItemUpdateDB", textBox1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferItem", "ItemUpdateField", textBox2.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferItem", "ItemStrDate", dateTimePicker1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferItem", "ItemEndDate", dateTimePicker2.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferItem", "ItemCYC", comboBox1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferItem", "ItemInterval", numericUpDown1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferItem", "ItemExecute", textBox3.Text);
            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton2.Checked)
            {
                label1.Visible = true;
                richTextBox1.Visible = true;
                checkBox2.Visible = true;
                checkBox3.Visible = false;
                groupBox2.Visible = false;
                label3.Visible = true;
                label4.Visible = true;
                textBox1.Visible = true;
                textBox2.Visible = true;
                checkBox1.Text = "采购订单抛转";
                checkBox2.Visible = true;
                label1.Text="提取采购订单";
                checkBox1.Checked = Convert.ToBoolean(XMLHelper.GetInnerTextByXpath("Configure.xml", "//POCheck"));
                checkBox2.Checked = Convert.ToBoolean(XMLHelper.GetInnerTextByXpath("Configure.xml", "//POCallGys"));
                richTextBox1.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//POLift")).ToString().Replace("<", "&lt;").Replace(">", "&gt;");
                richTextBox2.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//POUpdate")).ToString().Replace("<", "&lt;").Replace(">", "&gt;");
                textBox1.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//POUpdateDB"));
                textBox2.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//POUpdateField"));
                dateTimePicker1.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//POStrDate"));
                dateTimePicker2.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//POEndDate"));
                comboBox1.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//POCYC"));
                numericUpDown1.Text = XMLHelper.GetInnerTextByXpath("Configure.xml", "//POInterval");
                textBox3.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//POExecute"));
            }
            else
            {
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPO", "POCheck", checkBox1.Checked.ToString());
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPO", "POCallGys", checkBox2.Checked.ToString());
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPO", "POLift", richTextBox1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPO", "POUpdate", richTextBox2.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPO", "POUpdateDB", textBox1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPO", "POUpdateField", textBox2.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPO", "POStrDate", dateTimePicker1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPO", "POEndDate", dateTimePicker2.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPO", "POCYC", comboBox1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPO", "POInterval", numericUpDown1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPO", "POExecute", textBox3.Text);
            }
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton3.Checked)
            {
                label1.Visible = true;
                richTextBox1.Visible = true;
                checkBox2.Visible = true;
                checkBox3.Visible = false;
                groupBox2.Visible = false;
                label3.Visible = true;
                label4.Visible = true;
                textBox1.Visible = true;
                textBox2.Visible = true;
                checkBox1.Text = "采购退货单抛转";
                checkBox2.Visible = true;
                label1.Text = "提取采购退货单";
                checkBox1.Checked = Convert.ToBoolean(XMLHelper.GetInnerTextByXpath("Configure.xml", "//PRCheck"));
                checkBox2.Checked = Convert.ToBoolean(XMLHelper.GetInnerTextByXpath("Configure.xml", "//PRCallGys"));
                richTextBox1.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//PRLift")).ToString().Replace("<", "&lt;").Replace(">", "&gt;");
                richTextBox2.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//PRUpdate")).ToString().Replace("<", "&lt;").Replace(">", "&gt;");
                textBox1.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//PRUpdateDB"));
                textBox2.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//PRUpdateField"));
                dateTimePicker1.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//PRStrDate"));
                dateTimePicker2.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//PREndDate"));
                comboBox1.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//PRCYC"));
                numericUpDown1.Text = XMLHelper.GetInnerTextByXpath("Configure.xml", "//PRInterval");
                textBox3.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//PRExecute"));
            }
            else
            {
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPR", "PRCheck", checkBox1.Checked.ToString());
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPR", "PRCallGys", checkBox2.Checked.ToString());
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPR", "PRLift", richTextBox1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPR", "PRUpdate", richTextBox2.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPR", "PRUpdateDB", textBox1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPR", "PRUpdateField", textBox2.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPR", "PRStrDate", dateTimePicker1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPR", "PREndDate", dateTimePicker2.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPR", "PRCYC", comboBox1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPR", "PRInterval", numericUpDown1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferPR", "PRExecute", textBox3.Text);
            }
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton4.Checked)
            {
                label1.Visible = true;
                richTextBox1.Visible = true;
                checkBox2.Visible = false;
                checkBox3.Visible = false;
                groupBox2.Visible = false;
                label3.Visible = false;
                label4.Visible = false;
                textBox1.Visible = false;
                textBox2.Visible = false;
                checkBox1.Text = "库存明细抛转";
                checkBox2.Visible = false;
                label1.Text = "提取库存明细";
                checkBox1.Checked = Convert.ToBoolean(XMLHelper.GetInnerTextByXpath("Configure.xml", "//InvCheck"));
                richTextBox1.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//InvLift")).ToString().Replace("<", "&lt;").Replace(">", "&gt;");
                richTextBox2.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//InvUpdate")).ToString().Replace("<", "&lt;").Replace(">", "&gt;");
                textBox1.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//InvUpdateDB"));
                textBox2.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//InvUpdateField"));
                dateTimePicker1.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//InvStrDate"));
                dateTimePicker2.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//InvEndDate"));
                comboBox1.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//InvCYC"));
                numericUpDown1.Text = XMLHelper.GetInnerTextByXpath("Configure.xml", "//InvInterval");
                textBox3.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//InvExecute"));
            }
            else
            {
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferInv", "InvCheck", checkBox1.Checked.ToString());
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferInv", "InvLift", richTextBox1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferInv", "InvUpdate", richTextBox2.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferInv", "InvUpdateDB", textBox1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferInv", "InvUpdateField", textBox2.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferInv", "InvStrDate", dateTimePicker1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferInv", "InvEndDate", dateTimePicker2.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferInv", "InvCYC", comboBox1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferInv", "InvInterval", numericUpDown1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferInv", "InvExecute", textBox3.Text);
            }
        }

        private void radioButton5_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton5.Checked)
            {
                checkBox2.Visible = false;
                checkBox3.Visible = true;
                groupBox2.Visible = true;
                label3.Visible = false;
                label4.Visible = false;
                textBox1.Visible = false;
                textBox2.Visible = false;
                checkBox1.Text = "ASN转ERP进货";
                checkBox2.Visible = false;
                label1.Visible=false;
                richTextBox1.Visible = false;
                checkBox1.Checked = Convert.ToBoolean(XMLHelper.GetInnerTextByXpath("Configure.xml", "//ASNCheck"));
                richTextBox1.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//ASNLift")).ToString().Replace("<", "&lt;").Replace(">", "&gt;");
                richTextBox2.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//ASNUpdate")).ToString().Replace("<", "&lt;").Replace(">", "&gt;");
                textBox1.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//ASNUpdateDB"));
                textBox2.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//ASNUpdateField"));
                dateTimePicker1.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//ASNStrDate"));
                dateTimePicker2.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//ASNEndDate"));
                comboBox1.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//ASNCYC"));
                numericUpDown1.Text = XMLHelper.GetInnerTextByXpath("Configure.xml", "//ASNInterval");
                textBox3.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//ASNExecute"));
                checkBox3.Checked = Convert.ToBoolean(XMLHelper.GetInnerTextByXpath("Configure.xml", "//ERP_ASNCheck"));
                dateTimePicker4.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//ERP_ASNStrDate"));
                dateTimePicker3.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//ERP_ASNEndDate"));
                comboBox2.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//ERP_ASNCYC"));
                numericUpDown2.Text = XMLHelper.GetInnerTextByXpath("Configure.xml", "//ERP_ASNInterval");
                textBox4.Text = (XMLHelper.GetInnerTextByXpath("Configure.xml", "//ERP_ASNExecute"));

            }
            else
            {
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferASN", "ASNCheck", checkBox1.Checked.ToString());
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferASN", "ASNLift", richTextBox1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferASN", "ASNUpdate", richTextBox2.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferASN", "ASNUpdateDB", textBox1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferASN", "ASNUpdateField", textBox2.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferASN", "ASNStrDate", dateTimePicker1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferASN", "ASNEndDate", dateTimePicker2.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferASN", "ASNCYC", comboBox1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferASN", "ASNInterval", numericUpDown1.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferASN", "ASNExecute", textBox3.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferASN", "ERP_ASNCheck", checkBox3.Checked.ToString());
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferASN", "ERP_ASNStrDate", dateTimePicker4.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferASN", "ERP_ASNEndDate", dateTimePicker3.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferASN", "ERP_ASNCYC", comboBox2.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferASN", "ERP_ASNInterval", numericUpDown2.Text);
                XMLHelper.CreateOrUpdateXmlNodeByXPath("Configure.xml", "//TransferASN", "ERP_ASNExecute", textBox4.Text);

            }
        }

        private void Transfer_Load(object sender, EventArgs e)
        {
            radioButton1_CheckedChanged(sender, e);
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.Text=="按分钟")
            {
                textBox3.ReadOnly = true;
                textBox3.BackColor = Color.Gray;
                numericUpDown1.ReadOnly = false;
                numericUpDown1.BackColor = Color.Yellow;
            }
            else
            {
                numericUpDown1.ReadOnly = true;
                numericUpDown1.BackColor= Color.Gray;
                textBox3.ReadOnly = false;
                textBox3.BackColor = Color.Yellow;
            }
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.Text == "按分钟")
            {
                textBox4.ReadOnly = true;
                textBox4.BackColor = Color.Gray;
                numericUpDown2.ReadOnly = false;
                numericUpDown2.BackColor = Color.Yellow;
            }
            else
            {
                numericUpDown2.ReadOnly = true;
                numericUpDown2.BackColor = Color.Gray;
                textBox4.ReadOnly = false;
                textBox4.BackColor = Color.Yellow;
            }
        }
    }
}
